package com.pysoft.cms.web.controller.admin;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.pysoft.cms.dao.entity.Catalog;
import com.pysoft.cms.exception.ServiceException;
import com.pysoft.cms.service.CatalogService;

@Controller
@RequestMapping("/catalog")
public class CatalogController {
	@Autowired
	private CatalogService catalogService;
	@RequestMapping("/index")
	public String index() {
		return "admin/catalog/index";
	}
	
	@RequestMapping("/cview")
	public String crateView() {
		return "admin/catalog/catalog";
	}
	
	@RequestMapping("/uview")
	public String updateView() {
		return "admin/catalog/catalog";
	}
	
	@RequestMapping("/tree")
	public @ResponseBody List<Catalog> tree(Long siteId) {
		List<Catalog> catalogList = null;
		try {
			catalogList = catalogService.query(siteId);
		} catch (ServiceException e) {
			e.printStackTrace();
		}
		return catalogList;
	}
	
	@RequestMapping("/create")
	public @ResponseBody Map<String, Object> create(Catalog catalog) {
		Map<String, Object> r = new HashMap<String, Object>();
		try {
			catalog.setInsertuser("test");
			Date d = new Date();
			catalog.setInserttime(d);
			catalogService.create(catalog);
			r.put("suc", "1");
		} catch (ServiceException e) {
			e.printStackTrace();
			r.put("suc", "0");
		}
		return r;
	}

}
